package io.alvin.ch03;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 模拟线程池吞掉异常信息
 *
 * Created by Alvin on 2017/7/11.
 */
public class FatalThreadPoolDemo {

    public static class DivTask implements Runnable {

        int a,b;

        public DivTask(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public void run() {
            double re = a/b;
            System.out.println(re);
        }
    }

    public static void main(String[] args) {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
                0L, TimeUnit.SECONDS, new SynchronousQueue<>());
        for (int i = 0; i < 5; i++) {
            // pool.submit(new DivTask(100, i));   // 会隐藏错误
            pool.execute(new DivTask(100,i));   // 显示打印错误信息
        }
    }
}
